<template>
	<div class="wrapper">
		<!-- v-if 解决数据显示的不是第一个 -->
		<swiper :options="swiperOption" v-if = "showSwiper">
			<swiper-slide v-for="(item,index) of list" :key="item.id">
				<img class="swiper-img" :src="item.imgUrl"></img>
			</swiper-slide>
			<div class="swiper-pagination" slot="pagination"></div>

			<!--以下看需要添加-->
			<!-- <div class="swiper-scrollbar" slot="scrollbar"></div> //滚动条 -->
			<!-- 			<div class="swiper-button-prev" slot="button-prev"></div>
			<div class="swiper-button-next" slot="button-next"></div> -->
		</swiper>
	</div>

</template>

<script>
	export default {
		name: 'HomeSwiper',
		// 接收从父组件传过来的数据
		props: {
			list: Array
		},
		data() {
			return {
				swiperOption: {
					pagination: '.swiper-pagination',
					loop: true,
					autoplay: 3000,
					speed: 1000

				}
			}
		},
		computed: {
			showSwiper () {
				return this.list.length;
			}
		}
	};
</script>

<style scoped="scoped">
	.wrapper {
		width: 100%;
		height: 0;
		overflow: hidden;
		padding-bottom: 31.25%;
		background: #eee;
	}

	.swiper-img {
		width: 100%;
	}
</style>
